package com.byit.controller;

import com.byit.domain.AppComplaint;
import com.byit.enums.PromptInfo;
import com.byit.jwt.ann.JwtUser;
import com.byit.jwt.domain.JwtSession;
import com.byit.msg.MessageResult;
import com.byit.service.IAppComplaintService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @ClassName AppComplaintController
 * @Description 投诉
 * @Author lxp
 * @Date 2019-01-09 11:42
 **/
@RestController
@RequestMapping("/app/complaint")
public class AppComplaintController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IAppComplaintService appComplaintService;

    /**
     * 新增或修改投诉建议信息
     *
     * @param session
     * @param appComplaint
     * @return
     */
    @PostMapping("/add")
    public Object insertAppComplaint(@JwtUser JwtSession session, AppComplaint appComplaint) {


        Long userId = session.userId();
        try {
            if (null == appComplaint) {
                return MessageResult.warpper(PromptInfo.ERROR_PARAM_NOT_NULL);
            }

            appComplaint.setCreateTime(new Date());
            appComplaint.setUpdateTime(new Date());
            //// 加密用户密码
            appComplaint.setOperationId(userId);
            appComplaintService.insertOrUpdate(appComplaint);
            return MessageResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return MessageResult.error(e);
        }
    }

}
